package com.dhwl.hsh.merchant.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.dhwl.hsh.merchant.R;
import com.dhwl.hsh.merchant.common.Constant;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * 给司机捎句话
 *
 * @author Derek.Kidd
 * @time 2016/4/26 18:35
 */
public class AddWordsActivity extends BaseActivity {


    @Bind(R.id.edit_words)
    EditText editWords;
    @Bind(R.id.tv_input_number)
    TextView tvInputNumber;
    @Bind(R.id.checkBox_item_words)
    CheckBox checkBoxItemWords;
    @Bind(R.id.layout_words)
    RelativeLayout layoutWords;

    @Bind(R.id.btn_sure)
    Button btnSure;

    private String words;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_add_words;
    }

    @Override
    protected void initViews(Bundle savedInstanceState) {
        setTitleContent("给司机捎句话");

        editWords.addTextChangedListener(new TextWatcher() {
            @Override
            public void afterTextChanged(Editable editable) {
                String str = editable.toString();
                if (!TextUtils.isEmpty(str)) {
                    tvInputNumber.setText(str.length() + "/150");
                } else {
                    tvInputNumber.setText("0/200");
                }
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

        });
    }

    @Override
    protected void initData() {

    }

    @OnClick(R.id.layout_words)
    public void onCheckClick(View view) {
        checkBoxItemWords.setChecked(!checkBoxItemWords.isChecked());
    }

    @OnClick(R.id.btn_sure)
    public void onSureClick(View view) {
        if (checkBoxItemWords.isChecked()) {
            words = getString(R.string.words_for_driver_default);
        } else {
            words = editWords.getText().toString();
        }
        Intent intent = new Intent();
        intent.putExtra(Constant.Order.KEY_WORDS, words);
        setResult(RESULT_OK, intent);
        finish();
    }

}
